import jieba
import docx
import re
from pymongo import MongoClient

client = MongoClient('localhost',27017)
db = client.zuoye

# file = docx.Document('words.docx')
# str2 = ''
# for i in file.paragraphs:
#     str1 = i.text
#     str1 = str1.strip()
#     if str1.isdigit() == False:
#         zhmodel = re.compile(u'[\u4e00-\u9fa5]')
#         match = zhmodel.search(str1)
#         if match and '    ' not in str1:   
#             if '答案' not in str1:
#                 str2+=str1
#                 print(str2)
#             else:
#                 print(str1)

#                 use_1 = {
#                     "issue":str2,
#                     "result":str1,
#                 }    

#                 db.Q_A.insert_one(use_1)

#                 str2 = ''



# db.Q_A.create_index([('issue',1)])#创建索引

documents = db.Q_A.find()
inp = input('请输入关键词：')
list1 = []
for document in documents:
    # print(document['issue'])
    cut = jieba.cut(document['issue'])
    sss = (','.join(jieba.cut_for_search(document['issue'])))
    ssss = (','.join(cut))
    if inp in sss or inp==document['issue']:
        if document['issue'] not in list1:
            list1.append(document['issue'])
            print(document['issue'],re.findall(r'答案.*?.$',document['result'])[0])









